$(function () {
/*    var ue = UE.getEditor('editor');*/

    addmodel();




    var shopID=0;
    $("#save").click(function () {

        var commodityDetails = ue.getContent();
        var commodityName=$("#commodityName").val();//商品名称
        //商品状态(0下架、1上架、2暂停售卖、3过期)
        var  typeId=$('#typeList option:selected') .val();//选中的值   大类型
        var  clildTypeId=$('#smallTypeList option:selected') .val();//选中的值   小类型
        var  provinceId=$('#provinceList option:selected') .val();//选中的值   省会
        var  cityId=$('#cityList option:selected') .val();//选中的值   城市
        var  buyAmount=$('#buyAmountList option:selected') .val();//选中的值   是否可以选座
        var  isSeat=$('#isSeatList option:selected') .val();//选中的值   是否可以选座
        var  startTime=$("#start").text();
        var  endTime=$("#end").text();


        var buyAmountExplain=$("#buyAmountExplain").val();//限购说明
        var seatType=$("#seatType").val();//座位类型
        var childrenEntranceHint=$("#childrenEntranceHint").val();//儿童入场提示
        var entityTicket=$("#entityTicket").val();//实体票
        var electronicTicket=$("#electronicTicket").val();//电子票
        var prohibitedArticles=$("#prohibitedArticles").val();//禁止携带物品
        var otherExplain=$("#otherExplain").val();//其他说明

        $.getJSON("/commodityController/addTicketinginfo","buyAmountExplain="+buyAmountExplain+"&seatType="+seatType+"&childrenEntranceHint="+childrenEntranceHint+
            "&entityTicket="+entityTicket+"&electronicTicket="+electronicTicket+"&prohibitedArticles="+prohibitedArticles+"&otherExplain="+otherExplain+
            "&commodityName="+commodityName+"&typeId="+typeId+"&clildTypeId="+clildTypeId+
            "&provinceId="+provinceId+"&cityId="+cityId+"&buyAmount="+buyAmount+"&isSeat="+
            isSeat+"&commodityDetails="+commodityDetails+"&startTime="+startTime+"&endTime="+endTime,function (result) {
                shopID=result;
                if (result>0){
                    layer.alert("添加成功!!!")
                }else{
                    layer.alert("网络连接失败!!!")
                }
         })
    });

    //保存场次信息
    $("#save1").click(function () {
        var  placeId=$('#placeList option:selected') .val();//场地id
        var sessionTime=$("#sessionTime").val();//场次时间
        var  startTime=$("#start1").text();
        var  endTime=$("#end1").text();
        var arr = sessionTime.split(',');
        $("#ticketfilenames").html("");
        alert(placeId);
        $.getJSON("/ticket/selectAllByPlaceid","placeid="+placeId,function (resu) {
            $.each(resu, function (i, e) {
                $("#ticketfilenames").append("<input type='radio' class='ticke'  name='ticke' value='"+e.ticketfileid+"'>"+e.ticketfilename+"");
            });
        });
        $("#ccsj").html("");

        for(var item in arr){
            $("#ccsj").append("<input type='radio' class='sessionTimes'  name='sessionTimes' value='"+item+"'>"+arr[item]+"");
        }
         $.getJSON("/CommoditysessionController/saveCommodity","placeId="+placeId+"&sessiontime="+sessionTime
             +"&starttime="+startTime+"&endtime="+endTime,function (result) {
             if (result=="1"){
                 layer.alert("成功添加本场次!!!")
             }else{
                 layer.alert("网络连接失败!!!")
             }
         })
    });
    //保存sku信息
    $("#save2").click(function () {
       var sessionTimes= $("input[name='sessionTimes']:checked").val();//场次时间
       var  placeId=$('#placeList option:selected') .val();//场地id
       var ticketFileId= $("input[name='ticke']:checked").val();//票档
       var price=$("#price").val();//价格
       var isDis= $("input[name='isDis']:checked").val();//是否有折扣
       var discount=$("#discount").val();//折扣
        $.getJSON("/commodityController/addSku","commdityId="+shopID+"&sessionTime="+sessionTimes+"&placeId="+placeId
            +"&ticketFileId="+ticketFileId+"&price="+price+"&isDis="+isDis+"&discount="+discount,function (result) {
            if (result>0){
                layer.alert("成功添加到sku!!!")
            }else {
                layer.alert("网络连接失败!!!")
            }
        })
    });
    selectPlaceList();
    selectBigType();
    selectProvinceList();
    $("#typeList").change(function(){
        var id=$("#typeList option:selected").val();
        selectSmallTypeList(id);
    });
    $("#provinceList").change(function(){
        var id=$("#provinceList option:selected").val();
        selectSmallCityList(id);
    });
})
//查询所有大类型
function selectBigType(){
    $.getJSON("/showtype/father","fatherId=0",function(data){
        $("#typeList").html("<option value='0'>请选择类型名称</option>");
        $.each(data,function(i,e){
            $("#typeList").append("<option value='"+e.showTypeId+"'>"+e.typeName+"</option>");
        });
    });
}
//添加添加场次的表格
function addmodel(){
    $("#addChangCi").click(function(){
        $("#addd").after("<div class=\"row\">\n" +
            "                <div class=\"col-md-3\" >\n" +
            "                    <label class=\"label_name \">请&nbsp;设&nbsp;置&nbsp;场&nbsp;次&nbsp;时&nbsp;间：</label>\n" +
            "                    <input type=\"text\"  >\n" +
            "                </div>\n" +
            "                <div class=\"  col-md-3\" >\n" +
            "                    <label style=\"float:left\">开始时间：&nbsp;&nbsp;</label>\n" +
            "                    <p class=\"laydate-icon\"\n" +
            "                       style=\"width:200px; margin-right:10px; height:30px; line-height:30px; float:left\"><label style=\"margin-left: 206px;margin-top: 0px\"></label></p>\n" +
            "                </div>\n" +
            "                <div class=\"  col-md-3\" >\n" +
            "                    <label style=\"float:left\">结束时间：&nbsp;&nbsp;</label>\n" +
            "                    <p  class=\"laydate-icon\"  style=\"margin-left: 20px; width:200px;height:30px; line-height:30px; float:left\"></p>\n" +
            "                </div>\n" +
            "                <div class=\"col-md-3\">\n" +
            "                    <button type=\"button\" class=\"delChangCi layui-btn\" >删除场次</button>\n" +
            "                </div>\n" +
            "            </div>");
    })



    $("#dynamic").on("click",".delChangCi",function () {
        $(this).parent().parent().remove();
    })
}


//查询所有省会
function selectProvinceList(){
    $.getJSON("/city/hasFatherId","fatherId=0",function(data){
        $("#provinceList").html("<option value='0'>请选择省会名称</option>");
        $.each(data,function(i,e){
            $("#provinceList").append("<option value='"+e.cityId+"'>"+e.cityName+"</option>");
        });
    });
}
//根据大类型ID查询中类型
function selectSmallTypeList(id){
    $.getJSON("/showtype/father","fatherId="+id,function(data){
        $("#smallTypeList").html("<option value='0'>请选择子类名称</option>");
        $.each(data,function(i,e){
            $("#smallTypeList").append("<option value='"+e.showTypeId+"'>"+e.typeName+"</option>");
        });
    });
}
//根据省会查询城市
function selectSmallCityList(id){
    $.getJSON("/city/hasFatherId","fatherId="+id,function(data){
        $("#cityList").html("<option value='0'>请选择城市名称</option>");
        $.each(data,function(i,e){
            $("#cityList").append("<option value='"+e.cityId+"'>"+e.cityName+"</option>");
        });
    });
}
function  selectPlaceList() {
    $.getJSON("/place/findByAgentId",function(data){
        $("#placeList").html("<option value='0'>请选择场地名称</option>");
        $.each(data,function(i,e){
            $("#placeList").append("<option value='"+e.placeid+"'>"+e.placename+"</option>");
        });
    });
}
